package com.shop2cn.iapi.sqpayment.parameter;

/**
 * (C) Copyright 2016 Ymatou (http://www.ymatou.com/).
 * <p>
 * All rights reserved.
 */

import org.apache.commons.lang3.StringUtils;


/**
 * 支付渠道枚举
 *
 * @author wangxudong 2016年5月20日 上午11:08:41
 */
public enum PayTypeEnum {
    MockPay(0), // 压测用的MOCK渠道

    AliPayAppHb(8), // 支付宝花呗App
    AliPayHbfq(9), // 支付宝花呗分期
    AliPayPc(10),
    AliPayApp(13),
    AliPayWap(11),

    /**************************  洋漪  ************************/

    AliPayHbfq_YY(1009),   // 支付宝花呗分期
    AliPayPc_YY(1010),    // 支付宝PC
    AliPayApp_YY(1013),   // 支付宝App
    AliPayWap_YY(1011),   // 支付宝Wap

    WeiXinJSAPI_YY(1014),
    WeiXinApp_YY(1015),
    WeiXinPc_YY(1016),
    WeiXinMiniApp_YY(1017),
    WeiXinLiveApp_YY(1019),

    /*********************************************************/

    WeiXinJSAPI(14),
    WeiXinApp(15),
    WeiXinPc(16),
    WeiXinMiniApp(17),
    WeiXinLiveApp(19),  // 海外直播扫货
    WeiXinLiveShopMiniApp(18), // 直播微店


    /*************** 全球优选 ******************************/
    GlobalWeiXinMiniApp(3017),
    GlobalWeiXinApp(3015),
    GlobalAliPayApp(3013),

    /*************** 全球优选 洋云 ******************************/
    GlobalWeiXinMiniApp_YY(3117),
    GlobalWeiXinApp_YY(3115),
    GlobalAliPayApp_YY(3113),
    
    GlobalWeiXinJSAPI_YY(3118),
    /*************** 全球优选 鱼多多 ******************************/
    FishMoreWeiXinApp(3215),
    FishMoreAliPayApp(3213),
    /*************** 抖音支付 ******************************/
    TouTiaoAliPay(2013),    // 头条支付宝
    CmbApp(50),         // 招行一网通

    ApplePay(60),       // ApplePay 浦发收单行
    ApplePay2(61),      // 支持ApplePay双商户号
    UnionPayApp(62),       // 云闪付APP
    UnionPayWap(63),       // 云闪付Wap
    MiPay(64),              // 小米支付
    HuaweiPay(65),          // 华为支付
    SamSungPay(66),         // 三星支付

    BaofooPay(70),      // 宝付
    BestPay(80),        // 翼支付
    /*************** 百度支付 ******************************/
    BaiduAliPay(4013),           // 支付宝APP
    BaiduWxH5Pay(4016),          // 微信H5
    /*************** 神器支付 ******************************/
    HipoPayWxApp(6000),
    HipoPayWxH5(6001),
    HipoPayWxH5New(6002),        // 飛界國際電子商務
    HipoPayWxH5MY(6003),        // 飞界国际贸易
    HipoPayAliWap(6006),        // 支付宝WAP
    HipoPayWeixinApp(6103),         // 微信app
    HipoPayAliApp(6107),            // 支付宝app
    ToutiaoHipoAliApp(6207), //头条支付宝APP
    FqlPayWxApp(91),
    FqlPay(90),         // 分期乐支付
    /***盛付通  ****/
    ShengPayWxApp(6010),       // 盛付通微信小程序
    ShengPayWxGzh(6011),        // 盛付通微信公众号
    ShengPayAliWap(6012),   //盛付通支付宝H5
    GodAliPayPc(6100);        //支付宝PC-商家收费（南通海象网络科技） ;

    private int code;

    PayTypeEnum(int code) {
        this.code = code;
    }

    public int code() {
        return this.code;
    }

    @Override
    public String toString() {
        return String.valueOf(code);
    }

    public static PayTypeEnum getByCode(int code) throws Exception{
        for (PayTypeEnum enumItem : PayTypeEnum.values()) {
            if (enumItem.code() == code) {
                return enumItem;
            }
        }
        throw new Exception("payType is invalid");
    }

    public static PayTypeEnum parse(String code) throws Exception {
        if (StringUtils.isBlank(code)) {
            throw new Exception("payType is null or empty");
        }

        return getByCode(Integer.parseInt(code));
    }

    /**
     * 传递给交易
     * @param payType
     * @return
     */
    public static String getThirdPartyName(PayTypeEnum payType) {
        switch (payType) {
            case AliPayAppHb:
                return "AliPayHb";
            case AliPayHbfq:
                return "AliPayHbfq";
            case AliPayHbfq_YY:
                return "AliPayHbfq2";
            case AliPayApp:
            case GlobalAliPayApp:
            case AliPayPc:
            case AliPayWap:
            case GlobalAliPayApp_YY:
            case FishMoreAliPayApp:
            case TouTiaoAliPay:
            case BaiduAliPay:
                return "Alipay";
            case AliPayApp_YY:
            case AliPayPc_YY:
            case AliPayWap_YY:
                return "Alipay2";
            case WeiXinApp:
            case WeiXinJSAPI:
            case WeiXinPc:
            case WeiXinMiniApp:
            case WeiXinLiveShopMiniApp:
            case WeiXinLiveApp:
            case GlobalWeiXinMiniApp:
            case GlobalWeiXinApp:
            case GlobalWeiXinMiniApp_YY:
            case GlobalWeiXinApp_YY:
            case GlobalWeiXinJSAPI_YY:
            case FishMoreWeiXinApp:
            case BaiduWxH5Pay:
                return "Weixin";
            case WeiXinApp_YY:
            case WeiXinJSAPI_YY:
            case WeiXinPc_YY:
            case WeiXinMiniApp_YY:
            case WeiXinLiveApp_YY:
                return "Weixin2";
            case CmbApp:
                return "CmbPay";
            case ApplePay:
            case ApplePay2:
                return "ApplePay";//支持ApplePay双商户号
            case UnionPayApp:
            case UnionPayWap:
                return "UnionPay";
            case MiPay:
                return "MiPay";
            case HuaweiPay:
                return "HuaweiPay";
            case SamSungPay:
                return "SamSungPay";
            case BaofooPay:
                return "BaofooPay";
            case BestPay:
                return "BestPay";
            case HipoPayWxApp:
            case HipoPayWxH5:
            case HipoPayWxH5New:
            case HipoPayWxH5MY:
            case HipoPayWeixinApp:
                return "HipoPay";
            case HipoPayAliWap:
            case HipoPayAliApp:
                return "HipoPayAli";
            case ToutiaoHipoAliApp:
                return "ToutiaoAli";
            case FqlPay:
            case FqlPayWxApp:
                return "FqlPay";
            case ShengPayWxApp:
            case ShengPayWxGzh:
            case ShengPayAliWap:
                return "ShengPay";
            case GodAliPayPc:
                return "GodAliPay";
            case MockPay:
                return "MockPay";
            default:
                return payType.toString();
        }
    }

    public static ChannelTypeEnum getChannelType(int payType) {
        if (payType == (PayTypeEnum.AliPayHbfq.code())
                || payType == (PayTypeEnum.AliPayApp.code())
                || payType == (PayTypeEnum.AliPayAppHb.code())
                || payType == (PayTypeEnum.AliPayPc.code())
                || payType == (PayTypeEnum.AliPayWap.code())
                || payType == (PayTypeEnum.AliPayHbfq_YY.code())
                || payType == (PayTypeEnum.AliPayApp_YY.code())
                || payType == (PayTypeEnum.AliPayPc_YY.code())
                || payType == (PayTypeEnum.AliPayWap_YY.code())
                || payType == (PayTypeEnum.FishMoreAliPayApp.code())
                || payType == (PayTypeEnum.GlobalAliPayApp.code())
                || payType == (PayTypeEnum.GlobalAliPayApp_YY.code())
                || payType == (PayTypeEnum.TouTiaoAliPay.code())
                || payType == (PayTypeEnum.BaiduAliPay.code())) {
            return ChannelTypeEnum.AliPay;
        } else if (payType == PayTypeEnum.WeiXinApp.code()
                || payType == PayTypeEnum.WeiXinMiniApp.code()
                || payType == PayTypeEnum.WeiXinLiveApp.code()
                || payType == PayTypeEnum.WeiXinLiveShopMiniApp.code()
                || payType == PayTypeEnum.WeiXinJSAPI.code()
                || payType == PayTypeEnum.WeiXinPc.code()
                || payType == PayTypeEnum.WeiXinMiniApp_YY.code()
                || payType == PayTypeEnum.WeiXinApp_YY.code()
                || payType == PayTypeEnum.WeiXinJSAPI_YY.code()
                || payType == PayTypeEnum.WeiXinPc_YY.code()
                || payType == PayTypeEnum.WeiXinLiveApp_YY.code()
                || payType == PayTypeEnum.FishMoreWeiXinApp.code()
                || payType == PayTypeEnum.GlobalWeiXinMiniApp.code()
                || payType == PayTypeEnum.GlobalWeiXinApp.code()
                || payType == PayTypeEnum.GlobalWeiXinMiniApp_YY.code()
                || payType == PayTypeEnum.GlobalWeiXinApp_YY.code()
                || payType == PayTypeEnum.GlobalWeiXinJSAPI_YY.code()
                || payType == PayTypeEnum.BaiduWxH5Pay.code()
        ) {
            return ChannelTypeEnum.WeiXinPay;
        } else if (payType == PayTypeEnum.CmbApp.code()) {
            return ChannelTypeEnum.CmbPay;
        } else if (PayTypeEnum.ApplePay.code() == (payType)
                || PayTypeEnum.ApplePay2.code() == (payType)) {//支持ApplePay双商户号
            return ChannelTypeEnum.ApplePay;
        } else if (PayTypeEnum.BaofooPay.code() == (payType)) {
            return ChannelTypeEnum.BaofooPay;
        } else if (PayTypeEnum.BestPay.code() == (payType)) {
            return ChannelTypeEnum.BestPay;
        } else if (PayTypeEnum.HipoPayWxApp.code() == (payType)
                || PayTypeEnum.HipoPayWxH5.code() == (payType)
                || PayTypeEnum.HipoPayWxH5New.code() == (payType)
                || PayTypeEnum.HipoPayWxH5MY.code() == (payType)
                || PayTypeEnum.HipoPayAliWap.code() == (payType)
                || PayTypeEnum.HipoPayWeixinApp.code() == (payType)
                || PayTypeEnum.HipoPayAliApp.code() == (payType)
                || PayTypeEnum.ToutiaoHipoAliApp.code() == (payType)
        ) {
            return ChannelTypeEnum.HipoPay;
        } else if (payType == PayTypeEnum.UnionPayApp.code()
                || payType == PayTypeEnum.UnionPayWap.code()
                || payType == PayTypeEnum.MiPay.code()
                || payType == PayTypeEnum.HuaweiPay.code()
                || payType == PayTypeEnum.SamSungPay.code()) {
            return ChannelTypeEnum.UnionPay;
        } else if (payType == PayTypeEnum.FqlPay.code()
                || payType == PayTypeEnum.FqlPayWxApp.code()
        ) {
            return ChannelTypeEnum.FqlPay;
        } else if (payType == PayTypeEnum.ShengPayWxGzh.code()
                || payType == PayTypeEnum.ShengPayWxApp.code()
                || payType == PayTypeEnum.ShengPayAliWap.code()
        ) {
            return ChannelTypeEnum.ShengPay;
        } else if (payType == PayTypeEnum.GodAliPayPc.code) {
            return ChannelTypeEnum.GodAliPay;
        } else {
            return ChannelTypeEnum.MockPay;
        }
    }
}
